package com.yww.leetcode2.hashtable;

import java.util.HashMap;

/**
 * @author yww
 * @description 1. 两数之和
 * @since 2024/11/12
 */
public class TwoSum1_03 {
    public int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> hashtable = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int s = target - nums[i];
            if (hashtable.containsKey(s)) {
                return new int[]{hashtable.get(s), i};
            }
            hashtable.put(nums[i], i);
        }
        return new int[0];
    }
}
